{include file="header.html"}
<body>

<div class="navBar">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView-x">我要合作</div>
</div>

<div class="operate-input main-top">
	<form action="wap.php?app=member&act=operate_input" method="post">
	<input type="hidden" name="gourl" value="wap.php?app=member&act=index" />
	<input type="hidden" name="goalert" value="提交成功，请耐心等待审核" />
	<ul class="tableView tableView-noMargin tableView-light">
		<li>
			<h1>
				<input type="text" name="name" id="name" />
			</h1>
		</li>
		<li>
			<h1>
				<input type="text" name="address" id="address" />
			</h1>
		</li>
		<li>
			<h1>
				<div></div>
				<span>请上传身份证正面照</span>
				<a href="javascript:void(0)" class="push-img idcard"><div>选择图片</div></a>
				<input type="hidden" name="idcard" id="idcard" />
			</h1>
		</li>
		<li>
			<h1>
				<div></div>
				<span>请上传营业执照</span>
				<a href="javascript:void(0)" class="push-img business_license"><div>选择图片</div></a>
				<input type="hidden" name="business_license" id="business_license" />
			</h1>
		</li>
	</ul>
	</form>
	<div class="buttonView">
		<a href="javascript:void(0)" class="btn">提交资料</a> <!--成功页面 "wap.php?tpl=operate.complete"-->
	</div>
</div>

{include file="footer.html"}
<script>
function selectImage(){
	$('.push-img').ajaxupload({
		url : 'api.php?app=member&act=operate_input_upload',
		name : 'pic',
		before : function(){
			$.overload();
		},
		callback : {
			success : function(json, status){
				if(json.error!=0){ $.overloadError(json.msg);return }
				$(this).next().val(json.data);
				$(this).find('div').html('已选择');
				$(this).prev().prev().css('background-image', 'url('+json.data+')');
			},
			error : function(xml, status, e){
				alert('Upload error\n'+e);
			}
		}
	});
}
$(function(){
	$('#name').placeholder('请输入店铺名称');
	$('#address').placeholder('请输入店铺地址');
	if(!$.browser.wx)selectImage();
	$('.btn').click(function(){
		if(!$('#name').val().length){
			$.overloadError('请输入店铺名称');
			return;
		}
		if(!$('#address').val().length){
			$.overloadError('请输入店铺地址');
			return;
		}
		if(!$('#idcard').val().length){
			$.overloadError('请选择身份证图片');
			return;
		}
		if(!$('#business_license').val().length){
			$.overloadError('请选择营业执照图片');
			return;
		}
		$('form').submit();
	});
});

{if isset($weixin_sign_package)}
wx.config({
	debug: false,
	appId: '{$weixin_sign_package.appId}',
	timestamp: '{$weixin_sign_package.timestamp}',
	nonceStr: '{$weixin_sign_package.nonceStr}',
	signature: '{$weixin_sign_package.signature}',
	jsApiList: [
		'chooseImage',
		'uploadImage'
	]
});
wx.ready(function(){
	/*//
	wx.checkJsApi({
		jsApiList: [ //需要检测的JS接口列表
			'chooseImage',
			'uploadImage'
		],
		success: function(res){
			alert($.debug(res));
		}
    });
	//*/
	$('.push-img').click(function(){
		var _this = $(this);
		wx.chooseImage({
			success : function(res){
				var localId = res.localIds; //返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
				$.overload('正在上传...');
				setTimeout(function(){
					wx.uploadImage({
						localId: localId.toString(), //需要上传的图片的本地ID，由chooseImage接口获得
						isShowProgressTips: 0, //默认为1，显示进度提示
						success: function(res){
							var serverId = res.serverId; //返回图片的服务器端ID
							$.postJSON('api.php?app=member&act=operate_input_upload', { image_id:serverId }, function(json){
								if(json.error!=0){ $.overloadError(json.msg);return }
								_this.next().val(json.data);
								_this.find('div').html('已选择');
								_this.prev().prev().css('background-image', 'url('+json.data+')');
							});
						},
						fail: function(res){
							$.overload(false);
							alert($.debug(res));
						}
					});
				}, 100);
			}
		});
	});
});
{/if}
</script>